
import 'package:ad_plugin/ad_error.dart';
import 'package:ad_plugin/ad_listener.dart';
import 'package:ad_plugin/reward_video_ad.dart';
import 'package:ad_plugin/util/code_generate/ad_source_service.dart';
import 'package:flutter/material.dart';

/// FileName video_ad
/// @Author zhuqingfang
/// @Date 2022/9/29 3:59 下午
/// @Description video ad
const String adSource = "topOn,google";

@AdSourceService(adSource: adSource)
class VideoAd {
  VideoAd._internal();

  static final VideoAd _instance = VideoAd._internal();

  factory VideoAd() => _instance;
  RewardVideoAd? rewardVideoAd;


  void load() {
    RewardVideoAd.load(
        placementId: 'b62b03c9447fd7',
        adLoadCallback: AdLoadCallback(
            onAdLoaded:(RewardVideoAd rewardVideoAd) {
              debugPrint('video ad load ');
              this.rewardVideoAd = rewardVideoAd;
            },
            onAdFailLoad: (RewardVideoAd rewardVideoAd,LoadAdError error) {
              debugPrint('video ad load error $error');
            }));
  }

  void show() {
    rewardVideoAd?.rewardVideoContentCallback = RewardVideoContentCallback(
        onAdShow: (RewardVideoAd rewardAd) {
          debugPrint('video ad onShow');
        },
        onAdDismiss: (RewardVideoAd rewardAd) {
          debugPrint('video ad onDismiss');
        },
        onAdClick: (RewardVideoAd rewardAd) {
          debugPrint('video ad onClick');
        },
        onAdReward: (RewardVideoAd rewardAd) {
          debugPrint('video ad onReward');
        },onPlayError: (RewardVideoAd rewardAd,ShowAdError showAdError){});
    rewardVideoAd?.play();
  }
}
